package controller;

import entity.Administrator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import service.AdministratorService;
import tool.JsonResult;

import javax.servlet.http.HttpSession;

@Controller//控制器注解
@RequestMapping("/admin")
public class AdministratorController {
    @Autowired
    private AdministratorService administratorService;


    @RequestMapping("login")
    @ResponseBody//页面406是服务器返回类型不正确
    public JsonResult login(String adminname, String adminpwd, HttpSession session){
        System.out.println("dolo");
        Administrator administrator=administratorService.getAdministratorByname(adminname);

        System.out.println(administrator);
        if(administrator==null){
            return new JsonResult(false,10001,"管理员不存在",null);
        }else if(!administrator.getPassword().equals(adminpwd)){
            return new JsonResult(false,10001,"密码不正确",null);
        }else{
            session.setAttribute("admin",administrator);
            return new JsonResult(true,10000,"登录成功",administrator);
        }
    }


}
